#ifndef __M_LOG_H__
#define __M_LOG_H__

#include <stdio.h>
#include <time.h>

#define INF 0
#define DEBUG 1
#define ERR   2
#define FATAL 3

#define LOGFILE stdout  //日志文件输出流
#define DEFULAT_LOG DEBUG    //默认日志等级，小于可以不输出

//do while(){}使其成为一个整体的代码块
#define LOG(leve,format, ...)do{\
    if(leve < DEFULAT_LOG)break;\
    time_t t = time(NULL);\
    struct tm *curTime = localtime(&t);\
    char logPre[32] = {0};\
    strftime(logPre,sizeof(logPre) - 1,"%H:%M:%S",curTime);\
    fprintf(LOGFILE,"[%s:%s:%d] " format "\n",logPre,__FILE__,__LINE__,##__VA_ARGS__);\
}while(0)

#define ILOG(format, ...) LOG(INF,format,##__VA_ARGS__)
#define DLOG(format, ...) LOG(DEBUG,format,##__VA_ARGS__)
#define ELOG(format, ...) LOG(ERR,format,##__VA_ARGS__)
#define FLOG(format, ...) LOG(FATAL,format,##__VA_ARGS__)
#endif